home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.02 Feb 91 / 4th Debugger Appl / 4th Class.c next >
Encoding:
C/C++ Source or Header  |  1990-02-28  |  13.0 KB  |  385 lines  |  [TEXT/KAHL]

  1. /************************************************************************/
  2. /*                                                                          */
  3. /*    Source   - 4th Class.c                                                */
  4. /*    Author   - Alexander S. Colwell, Copyright © 1990                    */
  5. /*                                                                        */
  6. /*    Purpose     - This 4th Dimension's External Area class.                */
  7. /*                                                                        */
  8. /************************************************************************/
  9.  
  10. #include "4th Class.h"                /* 4th Ext Area Class defs            */
  11.  
  12. C4th    *New(void);                    /* "New" function proto-type        */
  13.  
  14. pascal void    main(eaEvent, eaRect, eaName, eaObject)
  15.     EventRecord        *eaEvent;        /* External Area event pointer        */
  16.     Rect            *eaRect;        /* External Rect area pointer        */
  17.     char            *eaName;        /* External Area name pointer        */
  18.     C4th            **eaObject;        /* External Area object                */
  19.     {
  20.         WindowPtr    curWPtr;        /* Working current window pointer    */
  21.         C4th        *fake;            /* Working fake object for "Layouts"*/
  22.         
  23.            RememberA0();                /* Save register A0 for A4            */
  24.            SetUpA4();                    /* Setup register A4                */
  25.  
  26.         if (eaEvent->what == drawReq) {/* Check if "Layout" draw        */
  27.             eaEvent->message = 102;    /* Let's draw other "0101010101"    */
  28.             
  29.                fake = New();            /* Create fake object                */
  30.  
  31.                GetPort(&curWPtr);        /* Get current window pointer        */
  32.             fake->layout = TRUE;    /* Set layout update state            */
  33.                fake->wPtr = curWPtr;    /* Save window pointer                */
  34.                fake->name = eaName;    /* Save external area name            */
  35.                fake->event = eaEvent;    /* Save event record ptr            */
  36.                fake->drawArea = *eaRect;/* Setup drawing area                */
  37.                fake->prevArea = *eaRect;/* Setup previous area                */
  38.             fake->width = eaRect->right - eaRect->left;/* Set width        */
  39.             fake->height = eaRect->bottom - eaRect->top;/* Set height    */
  40.                fake->tmpRgn = NULL;    /* Invalidate region                */
  41.  
  42.             eaEvent->what = initEvt;/* Fake init event                    */
  43.                fake->Message();        /* Handle message                    */
  44.  
  45.             eaEvent->what = updateEvt;/* Fake update event                */
  46.                fake->Message();        /* Handle message                    */
  47.  
  48.             eaEvent->what = deInitEvt;/* Fake deinit event                */
  49.                fake->Message();        /* Handle message                    */
  50.  
  51.                SetPort(curWPtr);        /* Restore previous window port        */
  52.         }
  53.             
  54.         else {                        /* Do real-thing                    */
  55.         
  56.                if (eaEvent->what == initEvt) {/* Check if its initalization*/
  57.                    *eaObject = New();    /* Create new object                */
  58.                 (*eaObject)->layout = FALSE;/* Set not layout state        */
  59.                    (*eaObject)->tmpRgn = NULL;/* Invalidate region            */
  60.                    (*eaObject)->wPtr = NULL;/* Invalidate window pointer    */
  61.                    (*eaObject)->prevArea = *eaRect;/* Set previous rect area*/
  62.                }
  63.                    
  64.                if (*eaObject) {        /* Check if got object                */
  65.                    GetPort(&curWPtr);    /* Get current window pointer        */
  66.                    (*eaObject)->wPtr = curWPtr;/* Save window pointer        */
  67.                    (*eaObject)->name = eaName;/* Save external area name    */
  68.                    (*eaObject)->event = eaEvent;/* Save event record ptr    */
  69.                    (*eaObject)->drawArea = *eaRect;/* Setup drawing area    */
  70.                 (*eaObject)->width = eaRect->right - eaRect->left;
  71.                 (*eaObject)->height = eaRect->bottom - eaRect->top;
  72.                    (*eaObject)->Message();/* Handle message                */
  73.                    SetPort(curWPtr);    /* Restore previous window port        */
  74.                }
  75.            }
  76.            
  77.            RestoreA4();                /* Restore register A4                */
  78.     }
  79.     
  80. void    C4th::Message(void)            /* Dispatch message                  */
  81.     {
  82.         register short    what;        /* Working event type                */
  83.         Rect            wRect;        /* Working rect area                */
  84.         
  85.         SaveStates();                /* Save states for drawing            */
  86.         
  87.         switch(what = event->what) {/* Process event message            */
  88.             case nullEvent:            /* Null event handler                */
  89.                 Idle(); break;
  90.                 
  91.             case initEvt:            /* Init event                        */
  92.                 IExtArea(FALSE); break;
  93.                 
  94.             case deInitEvt:            /* Close event                        */
  95.                 Close(); break;
  96.                 
  97.             case cursorEvt:            /* Cursor event                        */
  98.                 Cursor(event->where); break;
  99.                 
  100.             case selectReq:            /* Selection request event            */
  101.                 if (keyBoardEvents)    /* Check if want keyboard selection    */
  102.                     event->message = 101;/* Set keyboard request        */
  103.                 break;
  104.                 
  105.             case activNote:            /* Activate selection event            */
  106.                 Select(); break;
  107.                 
  108.             case deActivNote:        /* Deactivate selection event        */
  109.                 Deselect(); break;
  110.                 
  111.             case scrollEvt:            /* Scroll event                        */
  112.                 Scroll(); break;
  113.                 
  114.             case undoEvt:            /* Edit's "Undo" event                */
  115.                 DoUndo(); break;
  116.                 
  117.             case cutEvt:            /* Edit's "Cut" event                */
  118.                 DoCut(); break;
  119.                 
  120.             case copyEvt:            /* Edit's "Copy" event                */
  121.                 DoCopy(); break;
  122.                 
  123.             case pasteEvt:            /* Edit's "Paste" event                */
  124.                 DoPaste(); break;
  125.                 
  126.             case clearEvt:            /* Edit's "Clear" event                */
  127.                 DoClear(); break;
  128.                 
  129.             case selectAllEvt:        /* Edit's "Select All" event        */
  130.                 DoSelectAll(); break;
  131.                 
  132.             case afterActivEvt:        /* After "ActivNote" event            */
  133.                 break;
  134.                 
  135.             case afterDeactivEvt:    /* After "DeactivNote" event        */
  136.                 break;
  137.                 
  138.             case activeIdleEvt:        /* Selection idle event                */
  139.                 break;
  140.                 
  141.              case updateEvt:            /* Update external area                */
  142.                 wRect = drawArea;    /* Set drawing area to erase        */
  143.                  EraseRect(&wRect);    /* Clear it now for updating        */
  144.                  Draw();                /* Do "Draw" method                    */
  145.                  break;
  146.                  
  147.              case mouseDown:            /* Mouse down in external area        */
  148.                  DoClick(event->where,event->modifiers,event->when);
  149.                  break;
  150.                  
  151.              case keyDown:            /* Key down event                    */
  152.              case autoKey:            /* Auto-key down event                */
  153.                  DoKeyDown(event->message & charCodeMask,
  154.                            (event->message & keyCodeMask) >> 8); break;
  155.                  
  156.             default:                /* Don't know this event            */
  157.                 break;
  158.         }
  159.         
  160.         if (what != deInitEvt)        /* Check if not closing                */
  161.             RestoreStates();        /* Restore drawing states            */
  162.     }
  163.     
  164. void    C4th::IExtArea(short getKeyBoard)/* Init external area method    */
  165.     {
  166.           short            rom;        /* Working ROM id                    */
  167.           short            machine;    /* Working Mac id                    */
  168.         register short    canDoIt;    /* Working can do it indicator        */
  169.         SysEnvRec        wSysEnv;    /* Working system configuration        */
  170.  
  171.         dirty = FALSE;                /* Mark ext area not dirty            */
  172.         active = FALSE;                /* Mark ext area not active            */
  173.         keyBoardEvents = getKeyBoard;/* Set get keyboard events    flag    */
  174.         tmpRgn = NewRgn();            /* Temporary region                    */
  175.  
  176.         originalMac = FALSE;        /* Set not using 128K/512K Macs        */
  177.         hasGraphicDevices = FALSE;    /* Set has no graphic devices        */
  178.         sysEnv.environsVersion = 0;    /* Set bogus system configuration    */
  179.         sysEnv.machineType = 0;
  180.         sysEnv.systemVersion = 0;
  181.         sysEnv.processor = 0;
  182.         sysEnv.hasFPU = FALSE;
  183.         sysEnv.hasColorQD = FALSE;
  184.         sysEnv.keyBoardType = 0;
  185.         sysEnv.atDrvrVersNum = 0;
  186.         sysEnv.sysVRefNum = 0;
  187.  
  188.           Environs(&rom,&machine);    /* Get Mac's evniroment                */
  189.           if (machine == macXLMachine)/* Check if Lisa clone                */
  190.               canDoIt = FALSE;        /* It's a Lisa computer!            */
  191.           else if (rom >= macIIROM)    /* It's Mac II                        */
  192.              canDoIt = TRUE;            /* It's Mac II computer                */
  193.           else if (rom >= macSEROM)    /* It's Mac SE                        */
  194.              canDoIt = TRUE;            /* It's Mac SE computer                */
  195.           else if (rom >= macPlusROM) {/* it's 128K rom                    */
  196.                                       /* Check if Mac 512KE computer        */
  197.              if (MemTop > (char *)(1024L * 512L))
  198.                 canDoIt = TRUE;        /* It's Mac 512K Enhanced            */
  199.              else
  200.                 canDoIt = TRUE;        /* Its Mac Plus computer            */
  201.           }
  202.           else  if (rom >= macROM) {    /* It's 64K rom, it's old one        */
  203.              canDoIt = FALSE;        /* It's original Mac!                */
  204.               originalMac = TRUE;    
  205.         }
  206.         if (canDoIt)  {                /* OK, we can do it!                */
  207.             
  208.                                       /* Check if SysEnvirons valid        */
  209.             if ((long)NGetTrapAddress(SysEnvironsTrap,OSTrap) != 
  210.                   (long)NGetTrapAddress(UnknownTrap,ToolTrap)) {
  211.                 SysEnvirons(1,&wSysEnv);/* Get system enviroment        */
  212.                 sysEnv = wSysEnv;    /* Save system configuration        */
  213.             }
  214.         
  215.                                     /* Check if "Graphics Device" valid    */
  216.              if ((long)NGetTrapAddress(GetDeviceListTrap,ToolTrap) !=
  217.                  (long)NGetTrapAddress(UnknownTrap,ToolTrap))
  218.                     hasGraphicDevices = TRUE;/* Mark it available            */
  219.         }
  220.     }
  221.     
  222. void    C4th::Close(void)            /* Close external area method        */
  223.     {
  224.         RestoreStates();            /* Restore drawing states            */
  225.         if (tmpRgn)                    /* Check if have temp region handle    */
  226.             DisposeRgn(tmpRgn);        /* Release temp region handle        */
  227.         tmpRgn = NULL;                /* Invalidate temp region handle    */
  228.         delete(this);                /* Release this object                */
  229.     }
  230.     
  231. void    C4th::Idle(void)            /* Idle method                        */
  232.     {
  233.         if (dirty) {                /* Check if it's dirty                */
  234.             Draw();                    /* Re-draw everything!!!            */
  235.             dirty = FALSE;            /* Reset dirty indicator            */
  236.         }
  237.     }
  238.     
  239. void    C4th::Cursor(Point pt)        /* Cursor over external area method    */
  240.     {
  241.         CursHandle    crossHdl;        /* Working cross cursor handle        */
  242.         
  243.         if (crossHdl = GetCursor(crossCursor))/* Check if got cursor    */
  244.             SetCursor(*crossHdl);    /* Set to cross cursor                */
  245.     }
  246.     
  247. void    C4th::Select(void)            /* Select external area method        */
  248.     {
  249.         active = TRUE;                /* Mark external area active        */
  250.     }
  251.     
  252. void    C4th::Deselect(void)        /* Deselect external area method    */
  253.     {
  254.         active = FALSE;                /* Mark external area not active    */
  255.     }
  256.     
  257. void    C4th::Scroll(void)            /* Scroll external area    method        */
  258.     {
  259.     }
  260.     
  261. void    C4th::Draw(void)            /* Draw external area method        */
  262.     {
  263.         Rect    wRect;                /* Working rect area                */
  264.         
  265.         wRect = drawArea;            /* Set drawing rect area            */
  266.         
  267.         PaintRect(&wRect);            /* Paint it "black" to show something*/
  268.     }
  269.     
  270. void    C4th::DoClick(Point pt,     /* Mouse-click in ext area method    */
  271.                       short modifiers, long ticks)
  272.     {
  273.     }
  274.     
  275. void    C4th::DoKeyDown(char theChar,/* Key-down method                    */
  276.                         Byte keyCode)
  277.     {
  278.     }
  279.  
  280. void    C4th::DoUndo(void)            /* Edit "Undo" method                */
  281.     {
  282.     }
  283.  
  284. void    C4th::DoCut(void)            /* Edit "Cut" method                */
  285.     {
  286.     }
  287.  
  288. void    C4th::DoCopy(void)            /* Edit "Copy" method                */
  289.     {
  290.     }
  291.  
  292. void    C4th::DoPaste(void)            /* Edit "Paste" method                */
  293.     {
  294.     }
  295.  
  296. void    C4th::DoClear(void)            /* Edit "Clear" method                */
  297.     {
  298.     }
  299.  
  300. void    C4th::DoSelectAll(void)        /* Edit "Select All" method            */
  301.     {
  302.     }
  303.  
  304. void    C4th::SaveStates(void)        /* Save for drawing                    */
  305.     {
  306.         GetPenState(&savePenState);    /* Get current pen states            */
  307.         PenNormal();                /* Normalize pen characteristics    */
  308.         saveFont = wPtr->txFont;    /* Save current text font's states    */
  309.         saveSize = wPtr->txSize;
  310.         saveStyle = wPtr->txFace;
  311.         saveMode = wPtr->txMode;
  312.     }
  313.  
  314. void    C4th::RestoreStates(void)    /* Restore drawing stuff            */
  315.     {
  316.             SetPenState(&savePenState);/* Restore pen states                */
  317.             TextFont(saveFont);        /* Restore text font's characteristics*/
  318.             TextSize(saveSize);
  319.             TextFace(saveStyle);
  320.             TextMode(saveMode);
  321.             prevArea = drawArea;        /* Save previous area                */
  322.             if (tmpRgn)                /* Check if has temporary region    */
  323.                EmptyRgn(tmpRgn);        /* Free-up some memory                */
  324.     }
  325.     
  326. short    C4th::TrackMouse(Point pt,RgnHandle rgn)/* Track mouse within region*/
  327.     {
  328.         register RgnHandle    wRgn;    /* Working region handle            */
  329.         register short        hilite = FALSE;/* Working hilite state        */
  330.         register short        status = FALSE;/* Working status indicator    */
  331.         
  332.         if (PtInRgn(pt,rgn)) {        /* Check if initially inside region    */
  333.             if (wRgn = NewRgn()) {    /* Check if got new region            */
  334.                 CopyRgn(rgn,wRgn);    /* Copy mouse's region                */
  335.                 InsetRgn(wRgn,1,1);    /* Shrink it a bit for hiliting        */
  336.                 while(Button()) {    /* Do while mouse is down            */
  337.                     GetMouse(&pt);    /* Get next mouse position            */
  338.                     if (PtInRgn(pt,rgn))/* Check if mouse inside region    */
  339.                         status = TRUE;/* Set inside the region            */
  340.                     else            /* Nope, outside region                */
  341.                         status = FALSE;/* Set outside of the region        */
  342.                     if (hilite != status) {/* Check if change hilite     */
  343.                         hilite = status;/* Reset hilite state            */
  344.                         HiliteMode &= 0x7f;/* Set highliting bit        */
  345.                         InvertRgn(wRgn);/* Invert it                    */
  346.                     }
  347.                 }
  348.                 if (hilite) {        /* Check if restore hilite state    */
  349.                     HiliteMode &= 0x7f;/* Set highliting bit            */
  350.                     InvertRgn(wRgn);/* Invert it                        */
  351.                 }
  352.                 DisposeRgn(wRgn);    /* Release working region handle    */
  353.             }
  354.         }
  355.         return(status);                /* Return status indicator            */
  356.     }
  357.     
  358. short    C4th::UsingColor(void)
  359.     {
  360.         register short    hasColor = TRUE;/* Working color indicator        */
  361.         register GDHandle theDevice;/* Working screen device            */
  362.         Rect            globalRect;    /* Working global external rect area*/
  363.         Rect            wRect;        /* Working window rect area            */
  364.  
  365.         if (sysEnv.hasColorQD) {    /* Check if using color                */
  366.             if (hasGraphicDevices) {/* Check if has graphic devices        */
  367.                 hasColor = TRUE;    /* Assume using color                */
  368.                 globalRect = drawArea;/* Setup global external rect area*/
  369.                 LocalToGlobal(&globalRect.top);/* Convert to global (h,v)*/
  370.                 LocalToGlobal(&globalRect.bottom);
  371.                 theDevice = GetDeviceList();/* Get main device            */
  372.                 while(hasColor && theDevice) {/* Search B&W device        */
  373.                                     /* Check if window within view        */
  374.                     if (SectRect(&globalRect,&(*(*theDevice)->gdPMap)->bounds,
  375.                                  &wRect))
  376.                         if ((*(*theDevice)->gdPMap)->pixelSize <= 2)
  377.                             hasColor = FALSE;
  378.                     theDevice = GetNextDevice(theDevice);/* Get next one*/
  379.                 }
  380.             }
  381.         }
  382.         return(hasColor);            /* Return color indicator            */
  383.     }
  384.     
  385. int    DummyProc() {}                    /* Dummy procedure                    */